package com.devbobcorn.nekoration.items;

import com.devbobcorn.nekoration.NekoColors.EnumWoodenColor;

import net.minecraft.util.collection.DefaultedList;
import net.minecraft.nbt.NbtCompound;
import net.minecraft.text.Text;
import net.minecraft.text.TranslatableText;
import net.minecraft.item.BlockItem;
import net.minecraft.item.ItemGroup;
import net.minecraft.item.ItemStack;
import net.minecraft.block.Block;

public class DyeableWoodenBlockItem extends BlockItem {
    public static final String COLOR = "color";

    public DyeableWoodenBlockItem(Block block, Settings settings) {
        super(block, settings);
    }

    @Override
    public void appendStacks(ItemGroup tab, DefaultedList<ItemStack> subItems) {
        if (this.isIn(tab)) {
            for (EnumWoodenColor color : EnumWoodenColor.values()) {
                ItemStack subItemStack = new ItemStack(this, 1);
                setColor(subItemStack, color);
                subItems.add(subItemStack);
            }
        }
    }
    
    public static boolean hasColor(ItemStack stack) {
        return stack.getOrCreateNbt().contains(COLOR);
    }

    public static EnumWoodenColor getColor(ItemStack stack) {
        NbtCompound compoundNBT = stack.getOrCreateNbt();
        return EnumWoodenColor.fromNBT(compoundNBT, COLOR);
    }

    public static void setColor(ItemStack stack, EnumWoodenColor color) {
        NbtCompound compoundNBT = stack.getOrCreateNbt();
        color.putIntoNBT(compoundNBT, COLOR);
    }

    @Override
    public Text getName(ItemStack stack) {
        return CaseTweak.getTweaked(new TranslatableText(this.getTranslationKey(stack), (new TranslatableText("color.wooden." + (hasColor(stack) ? getColor(stack).asString() : "unknown"))).getString()));
    }
}
